package com.ygq.springboot.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.generator.config.IFileCreate;
import com.ygq.springboot.entity.Person;
import com.ygq.springboot.mapper.PersonMapper;
import com.ygq.springboot.service.IPersonService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author jobob
 * @since 2021-05-27
 */
@Service
public class PersonServiceImpl extends ServiceImpl<PersonMapper, Person> implements IPersonService {
    @Autowired
    private PersonMapper personMapper;


    @Override
    public IPage<Person> findAll(String name, Integer sex, IPage<Person> page) {
        QueryWrapper<Person> queryWrapper = new QueryWrapper<>();
        if(name != null && !name.equals("")){
            queryWrapper.like("name",name);
        }
        if(sex != null && sex != -1) {
            queryWrapper.eq("sex", sex);
        }
        return personMapper.selectPage(page,queryWrapper);
    }
}

